#!/bin/bash
PROJ_PATH=$1
# Python
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Django
python manage.py makemigrations ui
python manage.py migrate
python manage.py collectstatic
# nohup python manage.py runserver 0.0.0.0:8000

# Gunicorn
sed -e ':a' -e " s|PROJECT_PATH|$PROJ_PATH|; ta" ./routing_django/gunicorn.template > /etc/systemd/system/gunicorn.service
sudo cp ./routing_django/gunicorn.socket /etc/systemd/system/gunicorn.socket
sudo systemctl daemon-reload
sudo systemctl restart gunicorn
#gunicorn --bind 0.0.0.0:8000 --log-level DEBUG --timeout 60 routing_django.wsgi

# NGINX
sed -e ':a' -e " s|PROJECT_PATH|$PROJ_PATH|; ta" ./routing_django/nginx.template > /etc/nginx/nginx.conf
#sudo ln -s /etc/nginx/sites-available/routing_django /etc/nginx/sites-enabled
sudo systemctl restart nginx

# iptables
#iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
#iptables -A INPUT -i eth0 -p tcp --dport 443 -j ACCEPT
#iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 443

# UFW
sudo ufw allow 'Nginx Full'
